from django.contrib import admin

# Register your models here.
from .models import *

from django.utils.safestring import mark_safe
from simpleui.admin import AjaxAdmin


@admin.register(SupportTopPicture)
class SupportTopPictureAdmin(AjaxAdmin):
    def upload_img(self, obj):
        try:
            img = mark_safe('<img src="%s" height="120px" />' % (obj.imgUrl.url,))
        except Exception as e:
            img = ''
        return img
        
    upload_img.short_description = '服务与支持顶部图片'
    upload_img.allow_tags = True
    
    ordering = ("id", )
    # 要显示的字段
    list_display = ("id", "upload_img")


    
@admin.register(SupportNews)
class SupportNewsAdmin(AjaxAdmin):
    def upload_img(self, obj):
        try:
            img = mark_safe('<img src="%s" height="120px" />' % (obj.imgUrl.url,))
        except Exception as e:
            img = ''
        return img
        
    upload_img.short_description = '新闻卡片图'
    upload_img.allow_tags = True
    
    ordering = ("id", )
    # 要显示的字段
    list_display = ("id", "title", "synopsis", "upload_img", "create_date")
    
@admin.register(SupportVideos)
class SupportVideosAdmin(AjaxAdmin):
    def upload_img(self, obj):
        try:
            img = mark_safe('<img src="%s" height="120px" />' % (obj.imgUrl.url,))
        except Exception as e:
            img = ''
        return img
        
    upload_img.short_description = '视频卡片图'
    upload_img.allow_tags = True
    
    ordering = ("id", )
    # 要显示的字段
    list_display = ("id", "title", "upload_img", "create_date")

@admin.register(SupportDownloads)
class SupportDownloadsAdmin(AjaxAdmin):
    
    ordering = ("id", )
    # 要显示的字段
    list_display = ("id", "title", "create_date", "file_url")

    